package servlet.book;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.Session;

import com.javabean.UserBean;
import com.sql.Book;

/**
 * Servlet implementation class ManageBook
 */
@WebServlet("/managebook")
public class ManageBook extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ManageBook() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		List bookinfo = new ArrayList();
		int page;
		page = Integer.parseInt((String)request.getParameter("page"));
		int rowcount,pagecount;
		
		Book book = new Book();
		bookinfo = book.listbook(page);
		rowcount = book.getRows();
		if(rowcount%3==0) {
			pagecount = rowcount/3;
		}
		else {
			pagecount = (rowcount/3)+1;
		}
		
		String mypage = Integer.toString(pagecount);
		request.setAttribute("pagecount", mypage);
		request.setAttribute("bookinfo", bookinfo);
		request.getRequestDispatcher("booklist.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
